// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from 'vue'
import App from './App'
import MuseUI from 'muse-ui'
import infiniteScroll from 'vue-infinite-scroll'
import axios from 'axios'
import VueAxios from 'vue-axios'

import 'muse-ui/dist/muse-ui.css'
// import 'assets/styles/main.css'
import VueRouter from 'vue-router'
import Index from './components/Index.vue'
import Profile from './components/Profile.vue'
import Register from './components/Register.vue'
import Rank from './components/Rank.vue'
import Detail from './components/Detail.vue'
import Login from './components/Login.vue'
import Tech from './components/Tech.vue'






Vue.use(MuseUI);
Vue.use(VueRouter);
Vue.use(infiniteScroll);
Vue.use(VueAxios, axios);



// Vue.axios.defaults.baseURL = 'http://wc.callmesoul.cn';
Vue.axios.defaults.headers.common['Authorization'] = "Bearer "+localStorage.token;
// Vue.axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
console.log(Vue.axios.defaults.headers.common);
console.log(Vue.axios.defaults.headers.post);
// Vue.axios.create({
//   baseURL: 'http://wc.callmesoul.cn',
//   timeout: 3000,
//   headers: {'Authorization': 'Bearer '+localStorage.token}
// });








const router = new VueRouter({
  routes: [
    // 动态路径参数 以冒号开头
    { path: '/',  redirect:'/index'},
    { path: '/index', component: Index,name:"index" },
    { path: '/profile', component: Profile },
    { path: '/register', component: Register },
    { path: '/rank', component: Rank },
    { path: '/tech', component: Tech },
    { path: '/login', component: Login,name:'login'},
    { path: '/detail/:id', component: Detail,name:'detail'}
  ]
})
router.beforeEach((to, from, next) => {
  var state=to.fullPath;
  console.log(state);
  if(!localStorage.token || localStorage.token===""){
    if(to.name!=="login"){
      location.href="/oauth/authorize?state="+state;
    }else{
      next();// 确保一定要调用 next()
    }
  }else{
    next(); // 确保一定要调用 next()
  //
  }
});
/* eslint-disable no-new */
new Vue({
  el: '#app',
  template: '<App/>',
  components: { App },
  router
})
